import { post, get, put, Delete, form } from "@/axios/http.js";
import { basicApi } from "@/api/index.js"
import { setCookie, removeCookie, getCookie } from "@/utils/auth";
//模块数据
export default {
    namespaced: true,
    state: {
        group: getCookie('group') ? JSON.parse(getCookie('group')) : {}
    },
    actions: {
        // 热门成果
        hotAchievement({}, params) {
            return get(basicApi.research.hotAchievement, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 热门活动
        hotActivity({}, params) {
            return get(basicApi.research.hotActivity, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 热门教研组
        hotTeachingResearchGroup({}, params) {
            return get(basicApi.research.hotTeachingResearchGroup, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 首页手搜索接口
        researchSearch({}, params) {
            return post(basicApi.research.researchSearch, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 统计数据
        researchStatis({}, params) {
            return get(basicApi.research.researchStatis, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 分页查询校验下的活跃、热门用户
        researchUserStatis({}, params) {
            return post(basicApi.research.researchUserStatis, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 教研活动
        activityCreate({}, params) {
            return post(basicApi.research.activityCreate, params).then(res => {
                if (res.data.code == 200) {
                    return res
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        activityPage({}, params) {
            return post(basicApi.research.activityPage, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        activityUpdate({}, params) {
            return post(basicApi.research.activityUpdate, params).then(res => {
                if (res.data.code == 200) {
                    return res
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        activityDel({}, params) {
            return Delete(basicApi.research.activityDel, params).then(res => {
                if (res.data.code == 200) {
                    return res
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 教研下教研组
        groupCreate({}, params) {
            return post(basicApi.research.groupCreate, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        groupPage({}, params) {
            return post(basicApi.research.groupPage, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        groupUpdate({}, params) {
            return post(basicApi.research.groupUpdate, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        groupDel({}, params) {
            return Delete(basicApi.research.groupDel, params).then(res => {
                if (res.data.code == 200) {
                    return res
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        // 教研分组
        groupUserCreate({}, params) {
            return post(basicApi.research.groupUserCreate, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        groupUserPage({}, params) {
            return post(basicApi.research.groupUserPage, params).then(res => {
                if (res.data.code == 200) {
                    return res.data.result
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        groupUserUpdate({}, params) {
            return post(basicApi.research.groupUserUpdate, params).then(res => {
                if (res.data.code == 200) {
                    return res
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
        groupUserDel({}, params) {
            return Delete(basicApi.research.groupUserDel, params).then(res => {
                if (res.data.code == 200) {
                    return res
                } else {
                    this._vm.$message.error(res.data.msg)
                }
            });
        },
    },
    mutations: {
        INIT_GROUP(state, params) {
            state.group = params
            setCookie('group', state.group)
        }
    }
};